<template>
  <div id="app">
    <Topbar :key="topBar"></Topbar>
    <Header></Header>
    <Login v-show="isShowModal"></Login>
    <router-view  @updateKey="updateKeyFn"/>
    <Footer></Footer>
    <transition name="slide">
      <Toast v-show="isShowToast"></Toast>
    </transition>
    
  </div>
</template>
<script>
import Topbar from "@/components/Topbar";
import Header from "@/components/Header";
import Footer from "@/components/Footer";
import Toast from "@/components/Toast";
import Login from "@/components/Login";
import {JingpinAPI,ReMenAPI} from "@/request/api.js";
import {mapState} from 'vuex'
export default {
  data(){
    return{
      topBar:0
    }
  },
  watch:{
    "$route.path":{
      handler(newValue,oldValue){
      if(newValue!=oldValue){
        this.topBar++
      }
    }
    }
  },
  computed:{
    ...mapState({
      isShowModal:state => state.showModal.isShowModal,
      isShowToast:state => state.showToast.isShowToast
    })
  },
  methods:{
    updateKeyFn(){
      this.topBar++
    }
  },
  components: {
    Topbar,
    Header,
    Footer,
    Login,
    Toast
  },
 async created() {
      console.log("环境变量值：",process.env.VUE_APP_BASE_URL);
    console.log("环境变量值：",process.env.VUE_APP_STATE_URL);
    // axios.get("/products/recommend").then((res) => {
    //   console.log(res);
    // });
    // JingpinAPI().then(res=>{
    //   console.log(res);
    // }),
    // ReMenAPI().then(res=>{
    //   console.log(res);
    // })
    let res1 = await JingpinAPI()
    // console.log("res1",res1);

    let res2 = await ReMenAPI()
    // console.log("res2",res2);
  },
};
</script>
<style lang="less">
*{
 a{
   color:#fff;
   text-decoration: none;
 }
}
.w{
  width: 1200px;
  margin: 0 auto;
}
/* 入场的起始状态 = 离场的结束状态 */
.slide-enter, .slide-leave-to{
  opacity: 0;
}

.slide-enter-active, .slide-leave-active{
  transition: opacity .3s linear;
}

.slide-enter-to, .slide-leave{
  opacity: 1;
}
</style>
